<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">

<ui:include src="/WEB-INF/includes/head.xhtml">
	<ui:param name="pageTitle" value="Schedule" />
</ui:include>
<h:body>
	<ui:include src="/WEB-INF/includes/menu.xhtml" />
	<h1>Schedule</h1>
	<h:form id="form">

		<!-- Error messages -->
		<p:messages id="messages" closable="true" />

		<p:panelGrid styleClass="noBorders">
			<p:row>
				<p:column>
					<h:outputLabel for="stationCombobox" value="Station" />
				</p:column>
				<p:column>
					<p:selectOneMenu id="stationCombobox"
						value="#{schedule.selectedStation}" required="true"
						requiredMessage="Please select station">
						<f:selectItem itemLabel="-- Select station --" itemValue="" />
						<f:selectItems value="#{schedule.stations}" var="station"
							itemValue="#{station}" />
						<f:ajax listener="#{schedule.stationChanged}"
							render="schedule_table messages" />
					</p:selectOneMenu>
				</p:column>
			</p:row>
			<p:row>
				<p:column>
					<p:spacer height="50" />
				</p:column>
			</p:row>
		</p:panelGrid>

		<!-- Schedule table -->
		<p:dataTable id="schedule_table" var="record"
			value="#{schedule.scheduleRecords}">
			<p:column headerText="Arrival">
				<h:outputText value="#{record.arrival}" />
			</p:column>
			<p:column headerText="Departure">
				<h:outputText value="#{record.departure}" />
			</p:column>
			<p:column headerText="Trip ID">
				<h:outputText value="#{record.trip}" />
			</p:column>
			<p:column headerText="Route">
				<h:outputText value="#{record.route}" />
			</p:column>
			<p:column headerText="Buy" style="width:4%">
				<p:commandButton id="buyButton" update=":buyTicketForm:display"
					oncomplete="PF('buyTicket').show()" icon="ui-icon-cart" title="Buy">
					<f:setPropertyActionListener target="#{buyTicket.tripID}"
						value="#{record.trip}" />
				</p:commandButton>
			</p:column>
		</p:dataTable>
	</h:form>

	<ui:include src="/WEB-INF/includes/buy-ticket.xhtml" />

</h:body>
</html>